FROM python:3.12-slim

# Metadata
LABEL maintainer="CTW Team"
LABEL description="Chatbot Workshop - Full Agent with Streamlit + LangChain"
LABEL version="2.0.0"

# Environment variables
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

# Install system dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Install Poetry
RUN pip install poetry

# Configure Poetry
ENV POETRY_NO_INTERACTION=1 \
    POETRY_VIRTUALENVS_IN_PROJECT=1 \
    POETRY_VIRTUALENVS_CREATE=1 \
    POETRY_CACHE_DIR=/tmp/poetry_cache

# Create working directory
WORKDIR /app

# Copy Poetry configuration files
COPY pyproject.toml poetry.lock ./

# Install dependencies (without root package)
RUN poetry install --no-root && rm -rf $POETRY_CACHE_DIR

# Copy project structure
COPY config/ ./config/
COPY src/ ./src/
COPY tabs/ ./tabs/
COPY data/ ./data/
COPY personas.json ./
COPY ui.py ./

# Expose Streamlit port
EXPOSE 8501

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:8501/_stcore/health || exit 1

# Command to run the application
CMD ["poetry", "run", "streamlit", "run", "ui.py", "--server.address", "0.0.0.0", "--server.port", "8501"]
